package com.banzhi.shop.activity;

import android.app.FragmentBreadCrumbs;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.banzhi.shop.R;
import com.banzhi.shop.base.BaseActivity;
import com.banzhi.shop.data.AgentTimeBean;
import com.banzhi.shop.model.AgentTimeCallBack;
import com.banzhi.shop.model.Impl.AgentTimeImpl;
import com.banzhi.shop.utils.NoTokenUtils;
import com.banzhi.shop.utils.ToastUtils;
import com.banzhi.shop.utils.Translucent;
import com.moor.imkf.receiver.NetWorkReceiver;

import org.json.JSONObject;

//剩余时间
public class RemainingTimeActivity extends BaseActivity implements AgentTimeCallBack {

    private TextView mTvShoperTime;
    private String mShoperTime;
    private TextView mTvStartTime;
    private TextView mTvEndTime;
    private AgentTimeImpl mAgentTime;
    private AgentTimeBean mBean;
    private WebView mWvRule;
    private ImageView mIvBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_remaining_time);
        Translucent.setTranslucent(this);
        initView();
        setListener();
     /*   Intent intent = getIntent();
        mShoperTime = intent.getStringExtra("shopertime");*/

        mAgentTime = new AgentTimeImpl();
        mAgentTime.getAgentTimeData(this);


    }

    private void setListener() {
        mIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    private void initView() {
        mIvBack = (ImageView) findViewById(R.id.iv_back);
        mTvShoperTime = (TextView) findViewById(R.id.tv_shoper_time);
        mTvStartTime = (TextView) findViewById(R.id.tv_start_time);
        mTvEndTime = (TextView) findViewById(R.id.tv_end_time);
        mWvRule = (WebView) findViewById(R.id.wv_rule);

    }

    @Override
    public void onGetAgentTimeDataSuccess(Object object) {
        mBean = (AgentTimeBean) object;
        showView();
    }

    private void showView() {
        mTvShoperTime.setText(mBean.getRestday());
        mTvStartTime.setText(mBean.getAgenttime());
        mTvEndTime.setText(mBean.getAgentendtime());

        WebSettings settings = mWvRule.getSettings();
/*        //      自适应屏幕
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        //扩大比例的缩放
        settings.setJavaScriptEnabled(true);*/

        mWvRule.loadDataWithBaseURL(null, mBean.getHtml(), "text/html", "utf-8", null);
    }

    @Override
    public void onGetAgentTimeDataError(Object object) {
        JSONObject jsonObject = (JSONObject) object;
        NoTokenUtils.loginOut(getParent(), jsonObject);
        ToastUtils.makeToastShort(jsonObject.optString("msg"));
    }
}
